/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbtesting;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author zorr
 */
public class CreateUser {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/playboxdb?user=root&password=toor");
            String newuser = "insert into usertab (username, zertifikat, Name, password) values (?,?,?,?)";

            PasswordService ps = PasswordService.getInstance();
            PreparedStatement pwstat = null;
            pwstat = conn.prepareStatement(newuser);
            String username = "ferdl";
            String password = "ferdlpw";
            pwstat.setString(1, username);
            pwstat.setString(2, "");
            pwstat.setString(3, "rulz");
            String hash = ps.getHash(password, username);
            pwstat.setString(4, hash);
            
            System.out.println("hash: " + hash);
            //sollte alles geklappt haben, ist rs = 1
            int rs = pwstat.executeUpdate();
            System.out.println("rs:" + rs);

            //verbindung wieder schließen
            conn.close();

        } catch (SQLException ex) {
            // Fehler behandeln
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }

    }
}
